package com.fzb.zrlog.simple.dao.impl;

import com.fzb.common.dao.impl.DAO;
import com.fzb.zrlog.simple.dao.api.ILogDAO;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Log extends DAO implements ILogDAO {

    public Log() {
        tableName = "log";
        pk = "logId";
    }

    @Override
    public Map<String, Object> getLogByLogId(Object id) {
        try {
            return queryFirst("select l.*,t.typeName,t.alias typeAlias from log l,type t where l.typeId=t.typeId and logId=?", id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return new HashMap<>();
    }

    @Override
    public Map<String, Object> getLogByLogIdA(Object id) {
        try {
            return set("alias", id).queryFirst(ALL);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Map<String, Object> getLastLog(int id) {
        return null;
    }

    @Override
    public Map<String, Object> getNextLog(int id) {
        return null;
    }

    @Override
    public int getMaxRecord() {
        return 0;
    }

    @Override
    public Map<String, Object> getLogsByPage(int page, int pageSize) {
        try {
            Map<String, Object> fullData = new HashMap<>();
            List<Map<String, Object>> rows = queryPagination("select l.*,t.typeName,t.alias typeAlias from log l,type t where l.typeId=t.typeId order by logId desc", page, pageSize);
            fullData.put("rows", rows);
            return fullData;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Map<String, Object> queryAll(int page, int pageSize) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Map<String, Object> getLogsBySort(int page, int pageSize,
                                             String typeAlias) {
        try {
            Map<String, Object> fullData = new HashMap<>();
            List<Map<String, Object>> rows = queryPagination("select l.*,t.typeName,t.alias typeAlias from log l,type t where l.typeId=t.typeId order by logId desc", page, pageSize);
            fullData.put("rows", rows);
            return fullData;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Map<String, Object> getArchives() {
        return new HashMap<>();
    }

    @Override
    public Map<String, Object> getLogsByTag(int page, int pageSize, String tag) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Map<String, Object> getLogsByData(int page, int pageSize, String date) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Map<String, Object> getLogsByTitleOrContent(int page, int pageSize,
                                                       String key) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public List<Object[]> getAllAlias() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void clickChange(int logId) {
        // TODO Auto-generated method stub

    }

    @Override
    public long getAllClick() {
        return 0;
    }

    @Override
    public int getLogIdByAlias(String para) {
        try {
            return (int) set("alias", para).queryFirst(pk);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
